package com.heima.common.exception;

import com.heima.common.dtos.ResponseResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/*
    全局异常处理器
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * @param e
     * @return ResponseResult
     * 捕获并处理自定义业务异常
     */
    @ExceptionHandler(value = LeaNewsException.class)
    public ResponseResult handleLeadNewsException(LeaNewsException e){
        //e是service层抛出的自定义业务异常
        return ResponseResult.errorResult(e.getStatus(),e.getMessage());
    }

    /**
     * @param e
     * @return ResponseResult
     * 捕获并处理系统异常
     */
    @ExceptionHandler(value = Exception.class)
    public ResponseResult handleException(Exception e){
        e.printStackTrace();
        //e是service层抛出的系统异常
        return ResponseResult.errorResult(500,"系统异常："+e.getMessage());
    }
}
